import React, { useState } from 'react';

import {
  DesktopOutlined,
  FileOutlined,
  PieChartOutlined,
  TeamOutlined,
  UserOutlined,
} from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Breadcrumb, Layout, Menu, theme } from 'antd';
import { Outlet, useNavigate } from 'react-router-dom';

const { Header, Content, Footer, Sider } = Layout;

type MenuItem = Required<MenuProps>['items'][number];

function getItem(
  label: React.ReactNode,
  key: string,
  icon?: React.ReactNode,
  children?: MenuItem[],
): MenuItem {
  return {
    key,
    icon,
    children,
    label,
  } as MenuItem;
}
// 设计并实现路由配置，确保路由正确渲染
const items: MenuItem[] = [
  getItem('首页', '/home', <PieChartOutlined />),
  getItem('热搜', '/rs', <DesktopOutlined />),
  getItem('小说', '/xs', <UserOutlined />,),
  getItem('电影', '/dy', <UserOutlined />,),
];


function App() {
  const nav = useNavigate()
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();


  const tz = (info) => {
    if (info.key) {
      nav(info.key)
    }
  }
  return (
    <div>
      {/* 集成 Ant Design 组件库并配置按需加载功能 */}
      {/* 实现素材图片中标题栏渲染，并支持点击切换高亮状态 */}
      <Layout style={{ minHeight: '100vh' }}>
        <Sider style={{ padding: 0, background: '#fd695d', }} collapsible collapsed={collapsed} onCollapse={(value) => setCollapsed(value)}>
          <div className="demo-logo-vertical" />
          <Menu style={{ padding: 0, background: '#fd695d', }} onClick={tz} theme="dark" defaultSelectedKeys={['1']} mode="inline" items={items} />
        </Sider>
        <Layout >
          <Header style={{ padding: 0, background: '#fd695d', }} />
          <Content style={{ margin: '0 16px' }}>
            <Breadcrumb style={{ margin: '16px 0' }} items={[{ title: 'User' }, { title: 'Bill' }]} />
            <div
              style={{
                padding: 24,
                minHeight: 360,
                background: colorBgContainer,
                borderRadius: borderRadiusLG,
              }}
            >
              <Outlet></Outlet>
              <h4>0=9999</h4>
            </div>
          </Content>
          <Footer style={{ textAlign: 'center' }}>
            Ant Design ©{new Date().getFullYear()} Created by Ant UED
          </Footer>
        </Layout>
      </Layout>
    </div>
  )
}

export default App